const jwt=require('jsonwebtoken')
const whiteList=['/login']
const auth=async(ctx,next)=>{
    if(whiteList.includes(ctx.path)){
        await next()
    }else{
        let token=ctx.request.header.cookie.token
        console.log(token)
        if(token){
            jwt.verify(token,'1906A')
            await next()
        }else{
            try{
                ctx.body={
                    code:304,
                    mes:'token验证失败'
                }
            }catch(err){
                ctx.body={
                    code:401,
                    mes:'无token'
                }
            }
        }
    }
}

module.exports={auth}